package com.woniuxy.buyer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.buyer.entity.Order;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 订单Mapper
 */
@Mapper
public interface OrderMapper extends BaseMapper<Order> {

    /**
     * 查询用户的兑换历史
     */
    @Select("SELECT o.*, ub.nickname as buyer_name, us.nickname as seller_name " +
            "FROM orders o " +
            "LEFT JOIN users ub ON o.buyer_id = ub.id " +
            "LEFT JOIN users us ON o.seller_id = us.id " +
            "WHERE o.buyer_id = #{buyerId} " +
            "ORDER BY o.create_time DESC")
    List<Order> selectOrdersByBuyerId(Long buyerId);
}
